const {
  getalllbabel,
  deleteone,
  addlabel,
  editlabel,
} = require("../services/label.services");

class LabelController {
  //获取所有标签
  async getalllbabel(ctx, next) {
    const { start, size, search } = ctx.request.query;
    try {
      const result = await getalllbabel(start || -1, size || -1, search || "");
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //删除标签
  async deleteone(ctx) {
    const id = ctx.request.params.id;
    try {
      const result = await deleteone(id);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }

  //添加标签
  async addlabel(ctx) {
    const body = ctx.request.body;
    try {
      const result = await addlabel(body);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }

  //修改标签内容
  async editlabel(ctx) {
    const body = ctx.request.body;
    try {
      const result = await editlabel(body);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
}

module.exports = new LabelController();
